<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA3qyl_FEhGYSK9pSjzs-SVBRRmxvsDchdZPynv1Lw2iDuExpu_hRedE5TdRiy6czrOuJj2d3qm2FCLA" type="text/javascript"></script>
  </head>
  <body onunload="GUnload()">

    
    <div id="message">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;markers&gt;<br></div>


    <script type="text/javascript">
    //<![CDATA[
    

    // delay between geocode requests - at the time of writing, 100 miliseconds seems to work well
    var delay = 100;


    if (GBrowserIsCompatible()) { 

      
      // ====== Create a Client Geocoder ======
      var geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      reasons[403]                      = "Error 403: Probably an incorrect error caused by a bug in the handling of invalid JSON.";
      
      // ====== Geocoding ======
      function getAddress(search, next) {
        geo.getLocations(search, function (result)
          { 
            // If that was successful
            if (result.Status.code == G_GEO_SUCCESS) {
              // Lets assume that the first marker is the one we want
              var p = result.Placemark[0].Point.coordinates;
              var lat=p[1];
              var lng=p[0];
              // Display the results in XML format
              var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" lat="' +lat+ '" lng="' +lng+ '"&gt;<br>';
              document.getElementById("message").innerHTML += xml;
            }
            // ====== Decode the error status ======
            else {
              // === if we were sending the requests to fast, try this one again and increase the delay
              if (result.Status.code == G_GEO_TOO_MANY_QUERIES) {
                nextAddress--;
                delay++;
              } else {
                var reason="Code "+result.Status.code;
                if (reasons[result.Status.code]) {
                  reason = reasons[result.Status.code]
                } 
                var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" error="' +reason+ '"&gt;<br>';
                document.getElementById("message").innerHTML += xml;
              }   
            }
            next();
          }
        );
      }



      // ======= An array of locations that we want to Geocode ========
      var addresses = [
                "C/ Conde De Salvatierra 14, València",
                "C/ Eduardo Boscá 16, 46023 Valencia",
      ];

      // ======= Global variable to remind us what to do next
      var nextAddress = 0;

      // ======= Function to call the next Geocode operation when the reply comes back

      function theNext() {
        if (nextAddress < addresses.length) {
          setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay);
          nextAddress++;
        } else {
          document.getElementById("message").innerHTML += "&lt;/markers&gt;";
        }
      }

      // ======= Call that function for the first time =======
      theNext();
  


    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm

    //]]>
    </script>
  </body>

</html>




